package com.crm.service.impl.courseregist;

import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.dao.mapper.courseregist.CourseRegistrationMapper;
import com.crm.dao.mapper.customMapper.courseregist.CourseRegistCustomMapper;
import com.crm.model.entity.courseregist.CourseRegistration;
import com.crm.model.entity.courseregist.CourseRegistrationExample;
import com.crm.model.qo.courseregist.AuditRegistListQO;
import com.crm.model.qo.courseregist.CourseRegistListQO;
import com.crm.model.vo.courseregist.AuditCancelVO;
import com.crm.model.vo.courseregist.AuditRegistListVO;
import com.crm.model.vo.courseregist.CourseRegistVO;
import com.crm.service.courseregist.CourseRegistDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Description: 课程报名
 * @Author lixq-f
 * @Date 2021/4/26
 * @Version V1.0
 **/
@Service
public class CourseRegistDbServiceImpl implements CourseRegistDbService {

    @Autowired
    private CourseRegistrationMapper registrationMapper;
    @Autowired
    private CourseRegistCustomMapper registCustomMapper;


    @Override
    public Boolean insert(CourseRegistration regist) {
        return registrationMapper.insert(regist) > 0;
    }

    @Override
    public Boolean update(CourseRegistration regist) {
        return registrationMapper.updateByPrimaryKeySelective(regist) > 0;
    }

    @Override
    public CourseRegistVO selectCourseRegById(String id) {
        CourseRegistVO registVO = registCustomMapper.selectCourseRegistById(id);
        return registVO;
    }

    @Override
    public Boolean deleteById(String id, short deleteStatus) {
        return registCustomMapper.deleteById(id, deleteStatus);
    }


    @Override
    public Boolean registCancel(String cancelPersonId, Date cancelTm, String id) {
        return registCustomMapper.registCancel(cancelPersonId, cancelTm, id);
    }

    @Override
    public List<CourseRegistration> selectListByCreatePeopleId(String createPelpleId) {
        CourseRegistrationExample example = new CourseRegistrationExample();
        CourseRegistrationExample.Criteria criteria = example.createCriteria();
        criteria.andCreatePeopleIdEqualTo(createPelpleId);
        criteria.andDeleteStatusEqualTo((short) StatusCodeEnum.NORMAL_CODE.getState());
        example.setOrderByClause("create_tm asc");
        return registrationMapper.selectByExample(example);
    }


    @Override
    public List<CourseRegistVO> selectCourseRegistList(short deleteStatus, String order, CourseRegistListQO registListQO) {
        return registCustomMapper.selectCourseRegistList(deleteStatus,order,registListQO);
    }


    @Override
    public Boolean batchInsert(List<CourseRegistration> registLst) {
        return registCustomMapper.batchInsert(registLst);
    }


    @Override
    public Boolean auditCancel(CourseRegistration regist) {
        return registrationMapper.updateByPrimaryKeySelective(regist) > 0;
    }


    @Override
    public List<CourseRegistration> getRegistByCourseIdAndCustomerId(String customerId, String courseId) {
        CourseRegistrationExample example = new CourseRegistrationExample();
        CourseRegistrationExample.Criteria criteria = example.createCriteria();
        criteria.andCustomerIdEqualTo(customerId);
        criteria.andCourseArrangeIdEqualTo(courseId);
        criteria.andRegistStatusEqualTo(0);
        criteria.andDeleteStatusEqualTo((short)0);
        return registrationMapper.selectByExample(example);
    }


    /**
     * @Description: 根据产品号更新报名状态为报名成功
     * @Param: [registLst]
     * @Return: java.lang.Boolean
     * @Author: lixq-f
     * @Date: 2021/6/11
     **/
    @Override
    public Boolean consumeNoMember(List<String> registLst) {
        return registCustomMapper.consumeNoMember(registLst) > 0;
    }


    /**
     * @Description: 根据报名ID修改报名状态、取消类型
     * @Param: [registLst]
     * @Return: java.lang.Boolean
     * @Author: lixq-f
     * @Date: 2021/6/11
     **/
    @Override
    public Boolean updateRegistStatusByRegistIds(List<String> registLst, int registStatus, int cancelType, int isConsume) {
        return registCustomMapper.updateRegistStatusByRegistIds(registLst, registStatus, cancelType, isConsume) > 0;
    }


    @Override
    public List<AuditRegistListVO> selectAuditRegistList(String order, AuditRegistListQO registListQO) {
        return registCustomMapper.selectAuditRegistList(order, registListQO);
    }
}
